import 'package:flutter/material.dart';
import 'package:lib_uikit/lib_uikit.dart';
import 'package:lib_uikit/widgets/gt_button_v3.dart';

///单元格背景色，默认背景色bg1;card背景色card1
enum GTCellTypeV3 { defaultType, cardType }

///cell单元格
class GTCellV3 extends StatelessWidget {
  final GTCellTypeV3? type;
  final String text;

  //右边箭头icon是否展示，默认展示，传false不展示
  final bool? iconVisible;

  //左边widget，根据业务需要传入 币种/icon/头像/checkbox等
  final Widget? leftWidget;

  //右边widget，根据业务需要传入 icon/checkbox/switch等
  final Widget? rightWidget;

  //左边副标题
  final String? leftSubTitle;

  //右边副标题
  final String? rightSubTitle;

  //右边副标题，在rightSubTitle下方
  final String? rightBottomSubTitle;
  final bool? showDivider;

  //右侧more样式,距离箭头icon2间距，箭头颜色icon3
  final String? moreText;

  //左轻右重样式，左边浅色，右边深色
  final bool? lightLeftStyle;

  final bool? isEnabled;

  final String? startButtonText;
  final IconData? buttonEndIcon;
  final VoidCallback? startButtonClick;

  ///展示说明icon（左边标题后面）
  final bool? showTips;

  ///说明icon点击事件
  final VoidCallback? tipsClick;
  final Color? endIconColor;

  const GTCellV3(
      {super.key,
      this.type = GTCellTypeV3.defaultType,
      required this.text,
      this.leftWidget,
      this.rightWidget,
      this.iconVisible = true,
      this.leftSubTitle,
      this.rightSubTitle,
      this.rightBottomSubTitle,
      this.showDivider = true,
      this.moreText,
      this.lightLeftStyle,
      this.isEnabled,
      this.startButtonText,
      this.buttonEndIcon,
      this.startButtonClick,
      this.showTips,
      this.tipsClick,
      this.endIconColor});

  @override
  Widget build(BuildContext context) {
    bool _showDivider = showDivider ?? true;
    bool _iconVisible = iconVisible ?? true;
    bool _lightLeftStyle = lightLeftStyle ?? false;
    Color background;
    switch (type ?? GTCellTypeV3.defaultType) {
      case GTCellTypeV3.defaultType:
        background = Colors.transparent;
        break;
      case GTCellTypeV3.cardType:
        background = GTColorsV3.card1.color;
        _showDivider = false;
        break;
    }

    if ((moreText ?? "").isNotEmpty) {
      _iconVisible = false;
    }
    TextStyle styleW400 = gtTextStyleW400(fontSize: 12, color: GTColorsV3.text3.color);
    TextStyle styleW500 =
        gtTextStyleW500(fontSize: 14, color: _lightLeftStyle ? GTColorsV3.text3.color : GTColorsV3.text1.color);

    TextStyle subTitleStyle = _lightLeftStyle
        ? gtTextStyleW500(fontSize: 12, color: GTColorsV3.text1.color)
        : gtTextStyleW400(fontSize: 12, color: GTColorsV3.text3.color);
    return Container(
      decoration: BoxDecoration(color: background, borderRadius: BorderRadius.circular(6)),
      child: Column(
        children: [
          Container(
            padding: EdgeInsets.all(12),
            constraints: const BoxConstraints(
              minHeight: 44,
            ),
            child: Row(
              children: [
                if (leftWidget != null) ...[
                  leftWidget!,
                  const SizedBox(
                    width: 8,
                  ),
                ],
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    GestureDetector(
                      onTap: () {
                        tipsClick?.call();
                      },
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          Text(
                            text,
                            maxLines: 1,
                            style: styleW500,
                          ),
                          if (showTips ?? false) ...[
                            const SizedBox(width: 4),
                            Icon(
                              GTIconFont.e9fe,
                              size: 12,
                              color: GTColorsV3.icon3.color,
                            ),
                          ]
                        ],
                      ),
                    ),
                    if ((leftSubTitle ?? "").isNotEmpty) ...[
                      const SizedBox(
                        height: 4,
                      ),
                      Text(
                        leftSubTitle ?? "",
                        style: styleW400,
                      ),
                    ],
                    if ((startButtonText ?? "").isNotEmpty) ...[
                      const SizedBox(
                        height: 6,
                      ),
                      GTButtonV3(
                        text: startButtonText ?? "",
                        buttonType: GTButtonTypeV3.text_blue,
                        buttonSize: GTButtonSizeV3.text12,
                        endIconFont: buttonEndIcon,
                        onPressed: startButtonClick,
                      ),
                    ],
                  ],
                ),
                if ((rightSubTitle ?? "").isNotEmpty) ...[
                  const SizedBox(
                    width: 12,
                  ),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: [
                        Text(
                          rightSubTitle ?? "",
                          style: (rightBottomSubTitle ?? "").isEmpty ? subTitleStyle : styleW500,
                          softWrap: true,
                        ),
                        if ((rightBottomSubTitle ?? "").isNotEmpty) ...[
                          const SizedBox(
                            height: 4,
                          ),
                          Text(
                            rightBottomSubTitle ?? "",
                            style: styleW400,
                          ),
                        ],
                      ],
                    ),
                  ),
                ],
                if ((rightSubTitle ?? "").isEmpty) ...[const Spacer()],
                if (rightWidget != null) ...[
                  const SizedBox(
                    width: 8,
                  ),
                  rightWidget!,
                ],
                if (_iconVisible) ...[
                  const SizedBox(
                    width: 8,
                  ),
                  Icon(
                    GTIconFont.e89d,
                    size: 16,
                    color: (isEnabled ?? true) ? endIconColor ?? GTColorsV3.icon1.color : GTColorsV3.icon7.color,
                  )
                ],
                if ((moreText ?? "").isNotEmpty) ...[
                  const SizedBox(
                    width: 12,
                  ),
                  Text(
                    moreText ?? "",
                    style: styleW400,
                  ),
                  const SizedBox(
                    width: 2,
                  ),
                  Icon(
                    GTIconFont.e8b6,
                    size: 12,
                    color: GTColorsV3.icon3.color,
                  )
                ],
              ],
            ),
          ),
          if (_showDivider) ...[
            Container(
              height: 0.5,
              color: GTColorsV3.divider2.color,
              width: double.infinity,
            )
          ],
        ],
      ),
    );
  }
}
